import type { Website } from "@/api/config";
import { websiteInfo } from "@/api/website";
import { defineStore } from "pinia";
import { ref } from "vue";


function initState() {
    const websiteInfo = ref<Website>({
        logo: '',
        full_logo: '',
        title: '',
        slogan: '',
        slogan_en: '',
        description: '',
        version: '',
        created_at: '',
        icp_filing: '',
        public_security_filing: '',
        bilibili_url: '',
        gitee_url: '',
        github_url: '',
        name: '',
        job: '',
        address: '',
        email: '',
        qq_image: '',
        wechat_image: '',
    })
    return { websiteInfo, websiteInitiallized: false }
}

export const useWebsiteStore = defineStore('website', () => {
    const state = ref(initState());
    const initiallizeWebsite = async () => {
        if (!state.value.websiteInitiallized) {
            const res = await websiteInfo();
            if (res.code === 0) {
                state.value.websiteInfo = res.data;
                state.value.websiteInitiallized = true;
            }
        }
    }
    return { state, initiallizeWebsite };
})